<template>
  <div>
    <TopFilter ref="formpanel1" :list="formList1" :cols="4" @filterChange="formchangeFun" @resetChange="resetFun" />
    <el-row :gutter="10">
      <el-col :span="24">
        <FilterTable
          ref="basetable"
          :columns="columns"
          :fetchapi="fetchApi"
          :params="fetchParams"
          :datakey="'rows'"
          :onColumnsChange="columns => (this.columns = columns)"
          :height="'200'"
          :isSelectColumn="false"
          :dataSource="toptablelistSource"
          :onEnterEvent="tableDbclickFun"
          selectionType="single"
          columnsRef="partPartOutboundPartSalesSalesOrderAdd"
        ></FilterTable>
      </el-col>
      <!-- <el-col :span="8">
        <FilterTable
          ref="tablehistory"
          :columns="rigcolumns"
          :onColumnsChange="columns => (this.rigcolumns = columns)"
          :isSelectColumn="false"
          :datakey="'rows'"
          :height="'200'"
          :dataSource="rigtablelistSource"
          selectionType="single"
          columnsRef="xkpjxsxzTableh"
        ></FilterTable>
      </el-col> -->
    </el-row>

    <FormPanel ref="formpanel2" :list="formList2" :labelWidth="95" :cols="4" :isSubmitBtn="false" @formChange="formchangeFuns" />
    <FilterTable
      ref="basetables"
      :columns="columns1"
      :dataSource="tablelistSource"
      :isSelectColumn="false"
      :datakey="'rows'"
      :onColumnsChange="columns1 => (this.columns1 = columns1)"
      :height="'200'"
      :onSyncTableData="tablechangeFun"
      columnsRef="partPartOutboundPartSalesSalesOrderAdd2"
    ></FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9999,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <el-button @click="closeDialog">关 闭</el-button>
      <el-button type="primary" @click="confirmHandle">保 存</el-button>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { isAuthorized } from '@/utils/index'; // 权限
import { StockParts, Storage, queryBrand, salesHistory } from '@/api/part/partOut/partSales/index';
import { getStroageList } from '@/api/part/partOutbound/partBreak';
import { findAllRepair } from '@/api/repair/basicParameters';
import { queryUnitCode } from '@/api/part/partInfo';
import Cookies from 'js-cookie';
import { userPriceJurisdiction } from '@/api/common/auth/employeeAuth';
import { getBrand } from '@/api/repair/basicParameters';
export default {
  name: '',
  mixins: [dictionary],
  props: ['customerCode', 'priceAddRate', 'salesBasePriceType', 'rate'],
  data() {
    this.basetable = null;
    this.basetables = null;
    this.tablehistory = null;
    return {
      formList1: this.createFrom(),
      formList2: this.createFroms(),
      fetchApi: StockParts,
      fetchParams: {
        xhrAbort: true
      },
      SALES_PRICE: null,
      columns: this.createTable(),
      columns1: this.createTables(),
      rigcolumns: this.createtightTable(),
      tablelistSource: [],
      toptablelistSource: [],
      tableslist: [],
      rigtablelistSource: [],
      storageList: [],
      InitSalePrace: 0, // 初始销售价格
      scale: 0, // 销售价格比例
      listRecive: [], // 定义接收数据
      listType: [],
      unitCode: [],
      typePrice: 0,
      listPrice: 0, // 价格
      getpartParams: {
        sort: 'STORAGE_CODE',
        STORAGE_CODE: '',
        PART_NO: '',
        CUSTOMER_CODE: ''
      },
      fromSubmitdata: null,
      initStorage: null
    };
  },
  computed: {
    priceLimit() {
      return this.scale * this.InitSalePrace;
    }
  },
  watch: {
    priceLimit(newVal, oldVal) {
      if (newVal) {
        // this.formList2.find(item => item.fieldName == 'PART_SALES_PRICE').min = newVal;
      }
    }
  },
  mounted() {
    // this.searchInitScale(); // 根据用户的userOrgId 查询用户价格权限
    this.basetable = this.$refs.basetable.$refs.pageTable;
    this.basetables = this.$refs.basetables.$refs.pageTable;
    // this.tablehistory = this.$refs.tablehistory.$refs.pageTable;
    this.searchstore();
    // this.queryBrand();
  },
  methods: {
    createFrom() {
      return [
        {
          type: 'SELECT',
          label: '仓库',
          fieldName: 'storageCode',
          itemList: []
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'PartNo'
        },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'partName'
        },
        {
          type: 'INPUT',
          label: '库位',
          fieldName: 'storagePositionCode'
        },
        // {
        //   type: 'SELECT',
        //   label: '品牌',
        //   fieldName: 'brand',
        //   itemList: []
        // },
        {
          type: 'SELECT',
          label: '配件类型',
          fieldName: 'partGroupCode',
          itemList: this.createDictList('8247')
        }
        // {
        //   type: 'INPUT',
        //   label: '备注',
        //   fieldName: 'description'
        // }
      ];
    },
    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.$index + 1}</span>;
          }
        },
        {
          title: '仓库',
          dataIndex: 'STORAGE_NAME',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '库位',
          dataIndex: 'STORAGE_POSITION_CODE',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件代码',
          dataIndex: 'PART_NO',
          showOverflowTooltip: true,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件名称',
          dataIndex: 'PART_NAME',
          showOverflowTooltip: true,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '配件类型',
          dataIndex: 'PART_GROUP_CODE',
          sorter: true,
          filter: true,
          dictItems: this.createDictList('8247'),
          filterItems: this.createDictList('8247'),
          filterType: 'checkbox'
        },
        {
          title: '终端建议零售VIP价格',
          dataIndex: 'NOT_TAX_INSTRUCT_PRICE',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '账面库存',
          dataIndex: 'STOCK_QUANTITY',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '最新进货价',
          dataIndex: 'LATEST_PRICE',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        }
      ];
    },
    createtightTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '终端建议零售VIP价格',
          dataIndex: 'NOT_TAX_INSTRUCT_PRICE',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '索赔价',
          dataIndex: 'CLAIM_PRICE',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '终端建议零售价格',
          dataIndex: 'INSURANCE_PRICE',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '账面库存',
          dataIndex: 'STOCK_QUANTITY',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '可用库存',
          dataIndex: 'USEABLE_STOCK',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '锁定数量',
          dataIndex: 'LOCKED_QUANTITY',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          filterType: 'checkbox',
          title: '配件类型',
          dataIndex: 'PART_GROUP_CODE',
          disabled: true,
          dictItems: this.createDictList('8247')
        }
      ];
    },
    createFroms() {
      return [
        {
          type: 'SELECT',
          label: '仓库',
          fieldName: 'STORAGE_CODE',
          itemList: [],
          disabled: true
        },
        {
          type: 'INPUT',
          label: '配件代码',
          fieldName: 'PART_NO',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '配件名称',
          fieldName: 'PART_NAME',
          disabled: true
        },
        // {
        //   type: 'SELECT',
        //   label: '价格类型',
        //   fieldName: 'PRICE_TYPE',
        //   initialValue: this.salesBasePriceType ? this.salesBasePriceType : 80501002,
        //   disabled: !isAuthorized('1313', '13131010'),
        //   clearable: false,
        //   itemList: this.createDictList('8050'),
        //   change: val => {
        //     this.changeType(val);
        //   }
        // },
        // {
        //   type: 'INPUT_NUMBER',
        //   label: '价格系数',
        //   fieldName: 'PRICE_RATE',
        //   min: 0,
        //   max: 9.99,
        //   precision: 2,
        //   hidden: !isAuthorized('1313', '13131009'),
        //   initialValue: this.priceAddRate ? this.priceAddRate : 1,
        //   change: val => {
        //     this.changecoefficient(val);
        //   }
        // },

        // {
        //   type: 'INPUT_NUMBER',
        //   label: '配件销售单价',
        //   fieldName: 'PART_SALES_PRICE',
        //   initialValue: 0,
        //   precision: 2,
        //   min: this.priceLimit,
        //   disabled: !isAuthorized('1313', '13131001'),
        //   rules: [{ required: true, message: '请输入配件销售单价', trigger: 'blur' }],
        //   change: val => {
        //     this.changeMoney(val);
        //   }
        // },
        {
          type: 'INPUT_NUMBER',
          label: '预留数量',
          fieldName: 'LOCKED_QUANTITY',
          initialValue: 1,
          min: 0.01,
          precision: 2,
          change: val => {
            this.changemNum(val);
          }
        }
        // {
        //   type: 'INPUT',
        //   label: '配件销售金额',
        //   fieldName: 'SALES_AMOUNT',
        //   precision: 2,
        //   disabled: true
        // },
        // {
        //   type: 'SELECT',
        //   label: '销售方式',
        //   fieldName: 'SALES_TYPE',
        //   initialValue: 80961001,
        //   itemList: this.createDictList('8096')
        // }
      ];
    },
    createTables() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '终端建议零售VIP价格',
          dataIndex: 'NOT_TAX_INSTRUCT_PRICE',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '索赔价',
          dataIndex: 'CLAIM_PRICE',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '终端建议零售价格',
          dataIndex: 'INSURANCE_PRICE',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '账面库存',
          dataIndex: 'STOCK_QUANTITY',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '可用库存',
          dataIndex: 'USEABLE_STOCK',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          title: '锁定数量',
          dataIndex: 'LOCKED_QUANTITY',
          sorter: true,
          filter: true,
          precision: 2,
          filterType: 'number'
        },
        {
          filterType: 'checkbox',
          title: '配件类别',
          dataIndex: 'PART_GROUP_CODE',
          disabled: true,
          dictItems: this.createDictList('8247')
        },
        {
          filterType: 'input',
          title: '单位',
          dataIndex: 'UNIT_NAME',
          initialValue: '',
          disabled: true,
          dictItems: this.unitCode
        }
      ];
    },
    // 品牌下拉框
    async queryBrand() {
      const res = await getBrand();
      // const res = await queryBrand();
      this.formList1.find(item => item.fieldName === 'brand').itemList = res.data.map(x => ({ text: x.BRAND_NAME, value: x.BRAND_CODE + '' }));
      // this.formList1.find(item => item.fieldName === 'brand').initialValue = res.data.find(item => item.BRAND_NAME == '奥迪').BRAND_CODE;
      try {
        const res3 = await queryUnitCode();
        this.unitCode = res3.data.map(x => ({ text: x.UNIT_NAME, value: x.UNIT_CODE }));
        this.columns1.find(x => x.dataIndex == 'UNIT_CODE').dictItems = this.unitCode;
        console.log(res3, 'res3:::');
      } catch (err) {
        console.log('获取单位失败', err);
      }
    },
    async searchInitScale() {
      let userOrgId = Cookies.get('userOrgId');
      const res = await userPriceJurisdiction(userOrgId);
      if (res.resultCode == 200) {
        this.scale = res.data[0].scale / 100;
      }
      console.log(res.data[0].scale / 100, '获取销售折扣信息');
      console.log(res, '获取销售折扣信息');
    },
    // 仓库下拉框
    async searchstore() {
      const fetch1 = getStroageList();
      const res = await fetch1;
      this.storageList = res.data.map(x => ({ value: x.STORAGE_CODE, text: x.STORAGE_NAME }));
      this.formList2.find(x => x.fieldName == 'STORAGE_CODE').itemList = this.formList1.find(item => item.fieldName === 'storageCode').itemList = this.storageList;

      // const fetch2 = findAllRepair();
      // let resdata = await fetch2;
      // this.initStorage = this.formList1.find(item => item.fieldName === 'storageCode').initialValue = resdata.data['1100'];
    },
    getStroageName(STORAGE_CODE) {
      const item = this.storageList.find(x => {
        return x.value == STORAGE_CODE;
      });
      return item ? item.text : '';
    },
    formchangeFun(val) {
      this.fetchParams = Object.assign({}, val);
    },
    resetFun() {
      this.$nextTick(() => {
        this.formList1.find(x => x.fieldName == 'storageCode').initialValue = this.initStorage;
      });
    },
    formchangeFuns(val) {
      this.fromSubmitdata = val;
    },

    tableDbclickFun(val) {
      // 清空上一次的值
      this.tablelistSource = []; // 对table里面值进行清空
      this.rigtablelistSource = []; // 清空上次的历史查询记录
      this.listRecive = [];
      this.listType = val;
      // if (val.DOWN_TAG == 10041001) {
      //   this.formList2.find(item => item.fieldName === 'PART_NAME').disabled = true;
      // } else {
      //   this.formList2.find(item => item.fieldName === 'PART_NAME').disabled = false;
      // }
      this.formList2.find(item => item.fieldName === 'STORAGE_CODE').initialValue = val.STORAGE_CODE;
      this.formList2.find(item => item.fieldName === 'PART_NO').initialValue = val.PART_NO;
      this.formList2.find(item => item.fieldName === 'PART_NAME').initialValue = val.PART_NAME;
      // this.formList2.find(item => item.fieldName === 'PRICE_TYPE').initialValue = this.salesBasePriceType ? this.salesBasePriceType : 80501002;
      // this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue =
      // this.numFilter(val.SALES_PRICE) * this.numFilter(this.formList2.find(item => item.fieldName === 'PRICE_RATE').initialValue);
      this.formList2.find(item => item.fieldName === 'LOCKED_QUANTITY').initialValue = 1;
      // this.formList2.find(item => item.fieldName === 'SALES_AMOUNT').initialValue = this.numFilter(this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue);

      // if (val.OEM_TAG == 10451002) {
      //   this.formList2.find(item => item.fieldName === 'SALES_TYPE').initialValue = 80961001;
      //   this.formList2.find(item => item.fieldName === 'SALES_TYPE').disabled = true;
      // } else {
      //   this.formList2.find(item => item.fieldName === 'SALES_TYPE').disabled = false;
      // }
      // 第一次默认取的销售价的值
      this.listPrice = this.numFilter(val.SALES_PRICE);
      this.InitSalePrace = this.numFilter(val.SALES_PRICE);
      // this.getSalesHistory(val);
      this.tablelistSource = [val];
      this.changeType(this.salesBasePriceType);
    },
    async getSalesHistory(val) {
      let res = await salesHistory(val.STORAGE_CODE, val.PART_NO, this.customerCode);
      // this.tablehistory.EXECUTE_INSERT(res.data.rows);
    },

    // 校验单价
    checkPrice(rule, value, callback) {
      if (!value) {
        return callback(new Error(rule.message));
      } else {
        const reg = /^([1-9]\d*(\.\d*[1-9])?)|(0\.\d*[1-9])$/;
        if (reg.test(value)) {
          callback();
        } else {
          return callback(new Error(rule.message));
        }
      }
      callback();
    },
    // 校验数量
    checkNum(rule, value, callback) {
      let res = String(value).split('.');
      let num = 0;
      if (res[1] != undefined) {
        num = res[1].length;
      }
      if (!value) {
        return this.$notify.success({ title: '提示信息', message: rule.message });
      } else {
        if (value >= 0 && num <= 2) {
          callback();
        } else {
          return this.$notify.success({ title: '提示信息', message: rule.message });
        }
      }
      callback();
    },
    // 校验系数
    checkRate(rule, value, callback) {
      // 获取小数位的长度
      let res = String(value).split('.');
      let num = 0;
      if (res[1] != undefined) {
        num = res[1].length;
      }
      if (!value) {
        return this.$notify.success({ title: '提示信息', message: rule.message });
      } else {
        let a = value - 0.01;
        let b = 9.99 - value;
        if ((a >= 0 && b >= 0 && num <= 2) || value == 0) {
          callback();
        } else {
          return this.$notify.success({ title: '提示信息', message: rule.message });
        }
      }
      callback();
    },
    // 保留两位小数
    numFilter(value) {
      let realVal = parseFloat(value).toFixed(2);
      return realVal;
    },
    // 改变价格类型,每次改变价格类型时候都会对typePrice 和 listPrice 重新赋值用于计算
    changeType(val) {
      // 不含税成本价
      if (val == 80501001) {
        this.typePrice = val;
        // 判断字段是否为空
        if (this.listType.COST_PRICE != null) {
          // this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.COST_PRICE;
        } else {
          // this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
          this.listPrice = 0;
        }
        this.changeMoney(this.listPrice);
      } else if (val == 80501002) {
        // 含税销售价
        this.typePrice = val;
        if (this.listType.SALES_PRICE != null) {
          // this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.SALES_PRICE;
        } else {
          // this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
          this.listPrice = 0;
        }
        this.changeMoney(this.listPrice);
      } else if (val == 80501010) {
        // 含税采购价
        this.typePrice = val;
        if (this.listType.PLAN_PRICE != null) {
          // this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.PLAN_PRICE * (1 + Number(this.rate));
        } else {
          // this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
          this.listPrice = 0;
        }
        this.changeMoney(this.listPrice);
      } else if (val == 80501011) {
        this.typePrice = val;
        // 含税批发价
        if (this.listType.COST_WHOLESALES_PRICE != null) {
          // this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.COST_WHOLESALES_PRICE;
        } else {
          // this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
          this.listPrice = 0;
        }
        this.changeMoney(this.listPrice);
      }
      //  else if (val == 80501005) {
      //   this.typePrice = val;
      //   // 最新进货价
      //   if (this.listType.LATEST_PRICE != null) {
      //     this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.LATEST_PRICE;
      //   } else {
      //     this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
      //     this.listPrice = 0;
      //   }
      //   this.changeMoney(this.listPrice);
      // } else if (val == 80501006) {
      //   // 含税成本价
      //   this.typePrice = val; // 当时含税成本价对变量赋值，用于金额和参数变动计算
      //   if (this.listType.COST_PRICE != null) {
      //     this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.COST_PRICE + this.listType.COST_PRICE * this.rate;
      //   } else {
      //     this.listPrice = 0;
      //     this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
      //   }

      //   this.changeMoney(this.listPrice);
      // } else if (val == 80501007) {
      //   this.typePrice = val;
      //   // 终端建议零售价格
      //   if (this.listType.INSURANCE_PRICE != null) {
      //     this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.INSURANCE_PRICE;
      //   } else {
      //     this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
      //     this.listPrice = 0;
      //   }

      //   this.changeMoney(this.listPrice);
      // } else if (val == 80501009) {
      //   this.typePrice = val;
      //   // 销售限价
      //   if (this.listType.LIMIT_PRICE != null) {
      //     this.listPrice = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.listType.LIMIT_PRICE;
      //   } else {
      //     this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = 0;
      //     this.listPrice = 0;
      //   }
      //   this.changeMoney(this.listPrice);
      // }
    },

    changeMoney(val) {
      let scalePrice = Number(this.scale * this.InitSalePrace).toFixed(2);
      if (scalePrice > Number(val).toFixed(2)) {
        val = scalePrice;
      }
      if (this.typePrice == 80501006) {
        // 改变含税金额的值
        // this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.numFilter(val);
        if (this.listPrice != 0) {
          // this.formList2.find(item => item.fieldName === 'PRICE_RATE').initialValue = this.numFilter(val / this.listPrice); // 金额改变时候改变参数
        }
        const num = this.formList2.find(item => item.fieldName === 'LOCKED_QUANTITY').initialValue;
        // this.formList2.find(item => item.fieldName === 'SALES_AMOUNT').initialValue = this.numFilter(val * num);
      } else {
        // this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = this.numFilter(val);
        if (this.listPrice != 0) {
          // this.formList2.find(item => item.fieldName === 'PRICE_RATE').initialValue = this.numFilter(val / this.listPrice); // 金额改变时候改变参数
        }
        const num = this.formList2.find(item => item.fieldName === 'LOCKED_QUANTITY').initialValue;
        // this.formList2.find(item => item.fieldName === 'SALES_AMOUNT').initialValue = this.numFilter(val * num);
      }
    },
    // 改变系数参数
    changecoefficient(val) {
      if (this.typePrice == 80501006) {
        // 改变含税金额的值
        const num = this.formList2.find(item => item.fieldName === 'LOCKED_QUANTITY').initialValue;
        let money = this.numFilter(this.listPrice * val); // 参数改变时候，改变金额
        // this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = money;
        // this.formList2.find(item => item.fieldName === 'SALES_AMOUNT').initialValue = this.numFilter(money * num);
      } else {
        const num = this.formList2.find(item => item.fieldName === 'LOCKED_QUANTITY').initialValue;
        let money = this.numFilter(this.listPrice * val); // 参数改变时候，改变金额
        // this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue = money;
        // this.formList2.find(item => item.fieldName === 'SALES_AMOUNT').initialValue = this.numFilter(money * num);
      }
    },
    // 改变数量
    changemNum(val) {
      let reg = /^(-)?(?!0\d|[0.]+$)\d+(\.\d{1,2})?$/;
      let res = String(val).split('.');
      let num = 0;
      if (res[1] != undefined) {
        num = res[1].length;
      }
      if (!reg.test(val) || num > 2) {
        return this.$notify.warning({ title: '提示信息', message: '请输入非0的数值,保留2位小数' });
      } else {
        // const money = this.formList2.find(item => item.fieldName === 'PART_SALES_PRICE').initialValue;
        // this.formList2.find(item => item.fieldName === 'SALES_AMOUNT').initialValue = this.numFilter(val * money);
      }
    },
    // 关闭弹窗
    closeDialog() {
      this.$emit('close', false);
    },
    tablechangeFun(val) {
      this.tableslist = val;
    },
    // 添加事件提交表单
    confirmHandle() {
      // const nums = this.formList2.find(item => item.fieldName === 'PART_QUANTITY').initialValue;
      this.fromSubmitdata = null;
      this.$refs.formpanel2.SUBMIT_FORM();
      if (this.fromSubmitdata != null) {
        if (this.tableslist.length == 0) {
          return this.$notify.warning({ title: '提示信息', message: '需选中一条数据' });
        }
        // if (this.formList2.find(x => x.fieldName == 'SALES_TYPE').initialValue === 80961002 && this.formList2.find(x => x.fieldName == 'STORAGE_CODE').initialValue === 'OEMK') {
        //   return this.$notify.warning({ title: '提示信息', message: 'OEM库不能做一进一出操作' });
        // }
        if (this.formList2.find(item => item.fieldName == 'LOCKED_QUANTITY').initialValue > this.tableslist[0].STOCK_QUANTITY - this.tableslist[0].LOCKED_QUANTITY) {
          return this.$notify.warning({ title: '提示信息', message: '预留数量不能大于可用库存！' });
        }
        let formdata = Object.assign({}, this.tableslist[0], this.fromSubmitdata);
        // formdata.SALES_TYPE = formdata.SALES_TYPE ? formdata.SALES_TYPE : 80961002;
        // if (formdata.PART_SALES_PRICE < formdata.COST_PRICE) {
        //   this.$confirm('该配件发料价格低于成本价格，是否继续添加配件？', '提示', {
        //     confirmButtonText: '确定',
        //     cancelButtonText: '取消',
        //     type: 'warning'
        //   }).then(() => {
        //     this.$emit('changedata', formdata);
        //   });
        // } else {
        //   }
        this.$emit('changedata', formdata);
      }

      // if (this.formList2.find(x => x.fieldName == 'SALES_TYPE').initialValue === 80961001) {
      //   if (json.USEABLE_STOCK - nums < 0) {
      //     if (json.IS_NEGATIVE == 10041002) {
      //       return this.$notify.warning({ title: '提示信息', message: '该仓库不允许负库存!' });
      //     }
      //   }
      // }
      // let reg = /^(-)?(?!0\d|[0.]+$)\d+(\.\d{1,2})?$/;
      // let res = String(nums).split('.');
      // let num = 0;
      // if (res[1] != undefined) {
      //   num = res[1].length;
      // }
      // if (!reg.test(nums) || num > 2) {
      //   return this.$notify.warning({ title: '提示信息', message: '请输入正确的数值,保留2位小数' });
      // }
    }
  }
};
</script>
